using MediatR;
using SumerCoreDevOps.Application.Workflows.Queries;
using SumerCoreDevOps.Domain.Entities;
using SumerCoreDevOps.Infrastructure.Workflow;

namespace SumerCoreDevOps.Application.Workflows.Handlers;

/// <summary>
/// 根据ID获取工作流详情查询处理器
/// </summary>
public class GetWorkflowByIdQueryHandler : IRequestHandler<GetWorkflowByIdQuery, WorkflowDefinition?>
{
    private readonly WorkflowDefinitionManager _definitionManager;

    public GetWorkflowByIdQueryHandler(WorkflowDefinitionManager definitionManager)
    {
        _definitionManager = definitionManager;
    }

    public async Task<WorkflowDefinition?> Handle(GetWorkflowByIdQuery request, CancellationToken cancellationToken)
    {
        return await _definitionManager.GetWorkflowWithDetailsAsync(request.Id);
    }
}
